﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Skyper.Model;
namespace Skyper.ViewModel {
	public sealed class ChatViewModel : BaseViewModel {
		#region Fields
		private ChatModel active;
		#endregion
		#region Constructor
		public ChatViewModel() {

		}
		#endregion
		#region Private
		private void OnActiveChanged() {
			this.OnPropertyChanged("Active");
			this.OnPropertyChanged("Messages");
		}
		#endregion
		#region Property
		/// <summary>
		/// Gets the available chats chats.
		/// </summary>
		/// <value>The chats.</value>
		public ChatModel[] Chats {
			get {
				return App.Skype.Chats.ToArray();
			}
		}
		/// <summary>
		/// Gets or sets the active chat.
		/// </summary>
		/// <value>The active.</value>
		public ChatModel Active {
			get {
				if (active == null) {
					active = Chats[0];
				}
				return this.active;
			}
			set {
				if (this.active != value) {
					this.active = value;
					this.OnActiveChanged();
				}
			}
		}
		/// <summary>
		/// Gets the messages of an active chat.
		/// </summary>
		/// <value>The messages.</value>
		public ObservableCollection<MessageModel> Messages {
			get {
				if (this.active != null) {
					return App.Skype.GetMessages(this.active.Contact);
				}
				return null;
			}
		}
		#endregion
	}
}
